package com.mbc.rmt.manager;

import java.util.List;

import com.mbc.common.dao.CommonDAOFactory;
import com.mbc.common.dao.LogDAO;
import com.mbc.common.entities.Log;
import com.mbc.common.manager.AbstractMgr;
import com.mbc.common.param.CriteriaParams;
import com.mbc.common.utils.KeyGenerator;
import com.mbc.rmt.dao.COACurrencyDAO;
import com.mbc.rmt.dao.RemittanceDAOFactory;
import com.mbc.rmt.data.COACurrencyDataList;
import com.mbc.rmt.entities.COACurrency;

public class COACurrencyMgr extends AbstractMgr {

	private COACurrencyDAO coacurrencyDAO;
	private LogDAO logDAO;

	public COACurrencyMgr() {
	}

	public COACurrencyMgr(String sessionId) {
		this.sessionId = sessionId;
	}

	public void create(COACurrency entity) throws Exception {
		openConnection();
		try {
			coacurrencyDAO = RemittanceDAOFactory.getCOACurrencyDAO(dbManager
					.getConnection());
			entity.setCoacurrencykey(KeyGenerator.generateKey(getConnection()));
			coacurrencyDAO.create(entity);
			
			logDAO = CommonDAOFactory.getLogDAO(getConnection());
			Log l_logentity = new Log();
			l_logentity.setTablename("COACurrency");
			l_logentity.setLogkey(KeyGenerator.generateKey(getConnection()));
			l_logentity.setKey(entity.getCoacurrencykey());
			l_logentity.setUserid(entity.getUserid());
			l_logentity.setLogstatus(Log.__SAVE_DATA);
			logDAO.getData(l_logentity);
			
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public void update(COACurrency entity) throws Exception {
		openConnection();
		try {
			coacurrencyDAO = RemittanceDAOFactory.getCOACurrencyDAO(dbManager
					.getConnection());
			coacurrencyDAO.update(entity);
			
			logDAO = CommonDAOFactory.getLogDAO(getConnection());
			Log l_logentity = new Log();
			l_logentity.setTablename("COACurrency");
			l_logentity.setLogkey(KeyGenerator.generateKey(getConnection()));
			l_logentity.setKey(entity.getCoacurrencykey());
			l_logentity.setUserid(entity.getUserid());
			l_logentity.setLogstatus(Log.__UPDATE_DATA);
			logDAO.getData(l_logentity);
			
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public void delete(long key, long userid) throws Exception {
		openConnection();
		try {
			coacurrencyDAO = RemittanceDAOFactory.getCOACurrencyDAO(dbManager
					.getConnection());
			logDAO = CommonDAOFactory.getLogDAO(getConnection());
			Log l_logentity = new Log();
			l_logentity.setTablename("COACurrency");
			l_logentity.setLogkey(KeyGenerator.generateKey(getConnection()));
			l_logentity.setKey(key);
			l_logentity.setUserid(userid);
			l_logentity.setLogstatus(Log.__DELETE_DATA);
			logDAO.getData(l_logentity);
			coacurrencyDAO.delete(key);
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public COACurrency find(long key) throws Exception {
		openConnection();
		try {
			coacurrencyDAO = RemittanceDAOFactory.getCOACurrencyDAO(dbManager
					.getConnection());
			return coacurrencyDAO.find(key);
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public List<COACurrency> findAll() throws Exception {
		openConnection();
		try {
			coacurrencyDAO = RemittanceDAOFactory.getCOACurrencyDAO(dbManager
					.getConnection());
			return coacurrencyDAO.findAll();
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	public COACurrencyDataList findCOACurrencys(CriteriaParams cri)
			throws Exception {
		openConnection();
		try {
			coacurrencyDAO = RemittanceDAOFactory.getCOACurrencyDAO(dbManager
					.getConnection());
			return coacurrencyDAO.findCOACurrencys(cri);
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}

	/*public ArrayList<COACurrency> getCOACurrencyList(long coakey)
			throws Exception {
		openConnection();
		try {
			coacurrencyDAO = RemittanceDAOFactory.getCOACurrencyDAO(dbManager
					.getConnection());
			return coacurrencyDAO.getInfoList(coakey);
		} catch (Exception e) {
			throw e;
		} finally {
			closeConnection();
		}
	}*/

}
